import { constantRoutes, dynamicRoutes } from "@/router/index"
const routerData = {
    state: {
        routers: constantRoutes,
        addRouters: []
    },
    mutations: {
        SET_ROUTERS: (state, routers) => {
            state.addRouters = routers // 保存动态路由用来addRouter
            state.routers = constantRoutes.concat(routers) // 所有有权限的路由表，用来生成菜单列表
        }
    },
    actions: {
        generateRoutes({ commit }) {
            // 仅限演示
            function eachSelect(routers) {
                for (let j = 0; j < routers.length; j++) {
                    if (routers[j].children && routers[j].children.length) {
                        eachSelect(routers[j].children)
                    }
                }
            }
            let asyncRouter = [...dynamicRoutes] // 拷贝这个数组是因为做权限测试的时候可以从低级切回到高级角色，仅限演示，正式开发时省略这步直接使用 addRouter
            // eachSelect(asyncRouter)
            commit('SET_ROUTERS', asyncRouter)
        }
    }
}
export default routerData